//
//  QuestionTelCardView.m
//  EcmDoctor
//
//  Created by 张进 on 15/7/8.
//  Copyright (c) 2015年 张进. All rights reserved.
//

#import "QuestionTelCardView.h"
#import <UIImageView+AFNetworking.h>
#import "NetWorkUtil.h"
#import "AppUtils.h"

@implementation QuestionTelCardView


@synthesize userInfoView,maxWidth,maxHeight,msgInfoView,msgPicVoiceNumView,msgLabel,dateLabel,infoLabel,nickNameLabel,sexLabel,ageLabel,picLabel,voiceLabel,headImgView;

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

//- (instancetype)initWithFrame:(CGRect)frame{
//    
//    self = [super initWithFrame:frame];
//    
//    if (self) {
//        
//        
//        NSLog(@"");
//    }
//    
//    return self;
//}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
        //[self.topView setFrame:CGRectMake(0, 0, self.frame.size.width, self.topView.frame.size.height)];
//        [self setBackgroundColor:[UIColor colorWithRed:1.0 green:248.0/255 blue:238.0/255 alpha:1.0]];
        
    }
    return self;
}

+(QuestionTelCardView *)instanceQuestionTelCardViewWithSize:(CGSize)size{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"QuestionTelCardView" owner:nil options:nil];
    
    QuestionTelCardView *telView = [nibView objectAtIndex:0];
    //telView = [telView initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    telView.maxWidth = size.width;
    telView.maxHeight = size.height;
    return telView;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.headImgView.clipsToBounds = YES;
    self.headImgView.layer.cornerRadius = self.headImgView.bounds.size.width/2;
    
    //用户信息View
    CGRect userInfoRect = self.userInfoView.frame;
    userInfoRect.size.width = maxWidth;
    userInfoRect.origin.x=0;
    userInfoRect.origin.y = 0;
    self.userInfoView.frame = userInfoRect;
    //提醒View
    CGRect msgInfoViewRect = self.msgInfoView.frame;
    msgInfoViewRect.size.width = maxWidth;
    msgInfoViewRect.origin.y = maxHeight - msgInfoViewRect.size.height;
    self.msgInfoView.frame = msgInfoViewRect;
    
    //图片声音包裹View
    CGRect msgPicVoiceNumViewRect = self.msgPicVoiceNumView.frame;
    msgPicVoiceNumViewRect.origin.x = maxWidth - msgPicVoiceNumViewRect.size.width;
    msgPicVoiceNumViewRect.origin.y = maxHeight - msgInfoViewRect.size.height - msgPicVoiceNumViewRect.size.height - 12;
    self.msgPicVoiceNumView.frame = msgPicVoiceNumViewRect;
    //日期Label
    CGRect dateLabelRect = self.dateLabel.frame;
    dateLabelRect.origin.y = maxHeight - msgInfoViewRect.size.height - dateLabelRect.size.height - 15;
    self.dateLabel.frame = dateLabelRect;
    //提醒信息
    CGRect infoLabelRect = self.infoLabel.frame;
    infoLabelRect.size.width = maxWidth - 15 - 15;
    infoLabelRect.origin.y = maxHeight - infoLabelRect.size.height - 15;
    self.infoLabel.frame = infoLabelRect;
    
    //病情描述信息
    CGRect msgLabelRect = self.msgLabel.frame;
    msgLabelRect.size.width = maxWidth - 15 - 15;
    msgLabelRect.size.height = dateLabelRect.origin.y - msgLabelRect.origin.y - 8;
    self.msgLabel.frame = msgLabelRect;
    [self.msgLabel sizeToFit];
    
}

-(void)setTelModel:(TelModel *)telModel {
    
    [self.headImgView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", [NetWorkUtil getImagesBaseUrl], telModel.icon_Url]] placeholderImage:[UIImage imageNamed:@"icon"]];
    self.nickNameLabel.text = telModel.name;
    self.ageLabel.text = [telModel.age stringValue];
    self.sexLabel.text = telModel.sex;
    self.msgLabel.text = telModel.content;
    
    self.infoLabel.text = [NSString stringWithFormat:@"患者已经预约了 %@ %@ %@的电话问诊", telModel.info_order_date, [AppUtils weekForClinic:telModel.info_order_week], telModel.info_order_time];
    
    if (![telModel.voiceUrl isEqualToString:@""] && telModel.voiceUrl == nil) {
        self.voiceLabel.text = @"1";
    } else
        self.voiceLabel.text = @"0";
    
    self.picLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)telModel.picUrl.count];
}


//@property(nonatomic,strong) IBOutlet UILabel *msgLabel;
//@property(nonatomic,strong) IBOutlet UILabel *infoLabel;


@end
